package zucc.edu.cn.chengchengparttime.My;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;

import java.util.ArrayList;
import java.util.List;

import zucc.edu.cn.chengchengparttime.LoginAndReg.LoginActivity;
import zucc.edu.cn.chengchengparttime.LoginAndReg.LoginPhoneActivity;
import zucc.edu.cn.chengchengparttime.LoginAndReg.RegisterActivity;
import zucc.edu.cn.chengchengparttime.MainActivity;
import zucc.edu.cn.chengchengparttime.R;
import zucc.edu.cn.chengchengparttime.Work;

public class MyPersonalData extends AppCompatActivity implements View.OnClickListener{
    private Context context;
    private List<String> data=new ArrayList<>(); //数据列表

    private AppCompatButton btn_modifyPersonaldata;
    private ImageView goback;
    private TextView personal_data_ID;
    private TextView personal_data_school;
    private TextView personal_data_number;
    private TextView personal_data_gender;
    private TextView personal_data_phone;
    private TextView personal_data_intention1;
    private TextView personal_data_intention2;
    private TextView personal_data_registertime;

    private static final String DEBUG_TAG="Chengcheng Log2";
    private SQLiteDatabase mDatabase;// 数据库实例

    private void initView() {
        //初始化控件
        personal_data_ID=findViewById(R.id.personal_data_ID);
        personal_data_school=findViewById(R.id.personal_data_school);
        personal_data_number=findViewById(R.id.personal_data_number);
        personal_data_gender=findViewById(R.id.personal_data_gender);
        personal_data_phone=findViewById(R.id.personal_data_phone);
        personal_data_intention1 =findViewById(R.id.personal_data_intention1);
        personal_data_intention2=findViewById(R.id.personal_data_intention2);
        btn_modifyPersonaldata=findViewById(R.id.btn_modifyPersonaldata);
        personal_data_registertime=findViewById(R.id.personal_data_registertime);
        goback=findViewById(R.id.goback);

        //设置点击事件监听器
        btn_modifyPersonaldata.setOnClickListener(this);
        goback.setOnClickListener(this);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_my_personaldata);
        context=this.getBaseContext();

        mDatabase= SQLiteDatabase.openDatabase("/data/user/0/zucc.edu.cn.chengchengparttime/databases/Chengcheng.db",null,SQLiteDatabase.OPEN_READWRITE);//获取数据库
        Log.d("Chengcheng.db2","获取数据库"+mDatabase);

        initView();

        //查询兼职信息表的记录
        Cursor c=mDatabase.query("tbl_user", null, "UserID=?", new String[]{LoginActivity.getCurrentUser()}, null, null,null);
        c.moveToFirst();//游标移到第一条记录
        // 打印记录
        String[] x2 = new String[30];
        while(!c.isAfterLast()){
            String rowResults = "||";
            for (int i = 0; i < c.getColumnCount(); i++) {
                rowResults = rowResults.concat(c.getString(i) + "||");
                x2[i]=c.getString(i);
            }
            c.moveToNext();
        }
        c.close();//关闭游标工厂

        String nub=x2[6];
        personal_data_ID.setText(x2[0]);
        personal_data_school.setText(x2[4]);
        personal_data_gender.setText(x2[5]);
        personal_data_phone.setText(nub.substring(0,3)+"****"+nub.substring(7));
        personal_data_intention1.setText(x2[7]);
        personal_data_intention2.setText(x2[8]);
        personal_data_number.setText(x2[2]);
        personal_data_registertime.setText(x2[9]);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_modifyPersonaldata: //注册
                Toast.makeText(this.context, "点击了修改个人资料" , Toast.LENGTH_SHORT).show();
                //跳转到修改个人资料界面
                Intent intent = new Intent(MyPersonalData.this, MyPersonalData_Modify.class);
                startActivity(intent);
                finish();
                break;
            case R.id.goback:
                Toast.makeText(this.context, "点击了返回" , Toast.LENGTH_SHORT).show();
                //跳转到我的界面（首先要跳转到MainActivity，然后跳转到MyFragment）
                Intent i=new Intent();
                i.setClass(MyPersonalData.this, MainActivity.class);
                //一定要指定是第几个pager，这里填写3
                i.putExtra("id",3);
                startActivity(i);
                break;
        }
    }
}
